package com.grj.blog.a.imple;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.grj.blog.a.ArticleService;
import com.grj.blog.domain.BlogArticle;
import com.grj.blog.mapper.BlogArticleMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ArticleServiceImpl implements ArticleService {

    @Resource
    private BlogArticleMapper blogArticleMapper;
    @Override
    public List<BlogArticle> getArticleList() {
        return blogArticleMapper.selectList(null);
    }

    @Override
    public BlogArticle getArticleById(Long id) {
        return blogArticleMapper.selectById(id);
    }

    @Override
    public void publishArticle(BlogArticle article) {
        blogArticleMapper.insert(article);
    }

    @Override
    public void deleteArticle(Long id) {
        blogArticleMapper.deleteById(id);
    }

    @Override
    public void updateArticle(BlogArticle article) {
        blogArticleMapper.updateById(article);
    }

    @Override
    public Page<BlogArticle> search(String keyword, int pageNum, int pageSize) {
        return blogArticleMapper.selectPage(new Page<>(pageNum, pageSize), new QueryWrapper<BlogArticle>().like("title", keyword));
    }
}
